﻿using System;
using System.Collections.Generic;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Exceptions;

namespace SchEdu.Framework.Validators
{

    public class SetupTimeValidator : Validator
    {

        public SetupTimeValidator(SchEduData schEduData)
            : base(schEduData)
        {
        }
        #region IValidator Members

        public override void Validate()
        {
            SetupTimeList setupTimes = new SetupTimeList(SchEduData.SetupTime);

            foreach (SchEduDataSet.SetupTimeRow setupTime in setupTimes)
            {
                if (setupTime.IsFromOrderIDNull() == true)
                {
                    throw new ValidatorException(string.Format(Resources.SetupTimeDoesNotHaveFromOrder));
                }
                if (setupTime.IsToOrderIDNull() == true)
                {
                    throw new ValidatorException(string.Format(Resources.SetupTimeDoesNotHaveToOrder));
                }
                if (setupTime.IsMachineIDNull() == true)
                {
                    throw new ValidatorException(string.Format(Resources.SetupTimeDoesNotHaveMachine));
                }

            }

            foreach (SchEduDataSet.OrderRow fromOrder in SchEduData.Order)
            {
                foreach (SchEduDataSet.OrderRow toOrder in SchEduData.Order)
                {
                    foreach (SchEduDataSet.MachineRow machine in SchEduData.Machine)
                    {
                        SetupTimeList st = setupTimes.GetSetupTime(fromOrder, toOrder, machine);
                        if (st.Count > 0)
                        {
                            throw new ValidatorException(string.Format(Resources.DuplicateSetupTime,fromOrder.OrderNo,toOrder.OrderNo,machine.Name));
                        }
                    }
                }
            }
        }

        #endregion
    }
}
